package com.sunny.demo1;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

class CaculateHandler implements InvocationHandler {

    private Object obj;

    public CaculateHandler(Object obj){
        this.obj = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        this.doBefore();
        Object o = method.invoke(obj,args);
        this.doAfter();
        return o;
    }

    public void doBefore(){
        System.out.println("before doing...");
    }

    public void doAfter(){
        System.out.println("after doing...");
    }

}

